<div class="content">
    <div id="example_title">
        <h1>Expand/Collapse Items</h1>
        You can expand/collapse items of the sidebar during the run time. And starting with 2.0, you can specify where expand/collapse icon
        is displayed, on the left or right.
    </div>
    <div id="example_view"></div>
    <div id="example_code"></div>
</div>

<!--CODE-->
<div id="sidebar" style="height: 300px; width: 200px; float: left"></div>
<div style="margin-left: 220px;">
    <button class="w2ui-btn" onclick="action('collapse', ['level-1'])"> Collapse Level 1 </button>
    <button class="w2ui-btn" onclick="action('expand', ['level-1'])"> Expand Level 1 </button>
    <button class="w2ui-btn" onclick="action('toggleAlign')"> Toggle Align </button>
</div>
<div style="clear: both"/>

<!--CODE-->
<script type="module">
import { w2sidebar } from '__W2UI_PATH__'

let sidebar = new w2sidebar({
    box: '#sidebar',
    name: 'sidebar',
    nodes: [
        { id: 'level-1', text: 'Level 1', img: 'icon-folder', expanded: true,
            nodes: [
                { id: 'level-1-1', text: 'Level 1.1', icon: 'fa fa-star-o' },
                { id: 'level-1-2', text: 'Level 1.2', icon: 'fa fa-star-o' },
                { id: 'level-1-3', text: 'Level 1.3', icon: 'fa fa-star-o' }
            ]
        },
        { id: 'level-2', text: 'Level 2', img: 'icon-folder', expanded: true,
            nodes: [
                { id: 'level-2-1', text: 'Level 2.1', icon: 'fa fa-star-o' },
                { id: 'level-2-2', text: 'Level 2.2', icon: 'fa fa-star-o' },
                { id: 'level-2-3', text: 'Level 2.3', icon: 'fa fa-star-o' }
            ]
        }
    ]
})

window.action = function (method, ids) {
    if (method == 'toggleAlign') {
        sidebar.toggleAlign = sidebar.toggleAlign == 'left' ? 'right' : 'left'
        sidebar.refresh()
    } else {
        sidebar[method](...ids)
    }
}
</script>
